package com.nanhai.buddhist.college.module.collegebase.service.teacherremuneration;

import com.nanhai.buddhist.college.framework.common.util.collection.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.teacherremuneration.vo.*;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.teacherremuneration.TeacherRemunerationDO;
import com.nanhai.buddhist.college.framework.common.pojo.PageResult;

import com.nanhai.buddhist.college.module.collegebase.convert.teacherremuneration.TeacherRemunerationConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.mysql.teacherremuneration.TeacherRemunerationMapper;

import static com.nanhai.buddhist.college.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.nanhai.buddhist.college.module.collegebase.enums.ErrorCodeConstants.*;

/**
 * 教师薪酬 Service 实现类
 *
 * @author AKai
 */
@Service
@Validated
public class TeacherRemunerationServiceImpl implements TeacherRemunerationService {

    @Resource
    private TeacherRemunerationMapper teacherRemunerationMapper;

    @Override
    public String createTeacherRemuneration(TeacherRemunerationCreateReqVO createReqVO) {
        // 插入
        TeacherRemunerationDO teacherRemuneration = TeacherRemunerationConvert.INSTANCE.convert(createReqVO);
        teacherRemunerationMapper.insert(teacherRemuneration);
        // 返回
        return teacherRemuneration.getId();
    }

    @Override
    public void updateTeacherRemuneration(TeacherRemunerationUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateTeacherRemunerationExists(updateReqVO.getId());
        // 更新
        TeacherRemunerationDO updateObj = TeacherRemunerationConvert.INSTANCE.convert(updateReqVO);
        teacherRemunerationMapper.updateById(updateObj);
    }

    @Override
    public void deleteTeacherRemuneration(String id) {
        // 校验存在
        this.validateTeacherRemunerationExists(id);
        // 删除
        teacherRemunerationMapper.deleteById(id);
    }

    private void validateTeacherRemunerationExists(String id) {
        if (teacherRemunerationMapper.selectById(id) == null) {
            throw exception(TEACHER_REMUNERATION_NOT_EXISTS);
        }
    }

    @Override
    public TeacherRemunerationDO getTeacherRemuneration(String id) {
        return teacherRemunerationMapper.selectById(id);
    }

    @Override
    public List<TeacherRemunerationDO> getTeacherRemunerationList(Collection<String> ids) {
        return CollectionUtils.isEmpty(ids) ? Collections.emptyList() : teacherRemunerationMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<TeacherRemunerationDO> getTeacherRemunerationPage(TeacherRemunerationPageReqVO pageReqVO) {
        return teacherRemunerationMapper.selectPage(pageReqVO);
    }

    @Override
    public List<TeacherRemunerationDO> getTeacherRemunerationList(TeacherRemunerationExportReqVO exportReqVO) {
        return teacherRemunerationMapper.selectList(exportReqVO);
    }

}
